package com.yumeng.framework.auth.bean.authinfo;

import com.yumeng.common.auth.BaseAuthInfo;
import com.yumeng.common.data.enums.AuthMode;
import lombok.Setter;

import java.util.Objects;
import java.util.Set;

/**
 * 普通用户
 *
 * @author wxd
 * @date 2025/2/26 20:56
 */
@Setter
public class NormalAuthInfo extends BaseAuthInfo {

    private String identityId;
    private String identityName;
    private String authKey;
    private String credentials;
    private String salt;
    private String userTypes;
    private AuthMode authMode;
    private boolean enabled;
    private boolean accountLocked;
    private boolean accountExpired;
    private boolean credentialsExpired;
    private Set<String> authorities;

    @Override
    public String getIdentityId() {
        return identityId;
    }

    @Override
    public String getIdentityName() {
        return identityName;
    }

    @Override
    public String getAuthKey() {
        return authKey;
    }

    @Override
    public String getCredentials() {
        return credentials;
    }

    @Override
    public String getSalt() {
        return salt;
    }

    @Override
    public String getUserTypes() {
        return userTypes;
    }

    @Override
    public AuthMode getAuthMode() {
        return authMode;
    }

    @Override
    public boolean isEnabled() {
        return enabled;
    }

    @Override
    public boolean isAccountLocked() {
        return accountLocked;
    }

    @Override
    public boolean isAccountExpired() {
        return accountExpired;
    }

    @Override
    public boolean isCredentialsExpired() {
        return credentialsExpired;
    }

    @Override
    public Set<String> getAuthorities() {
        return authorities;
    }

    @Override
    public void eraseCredentials() {
        this.credentials = null;
        //this.salt = null;
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;
        NormalAuthInfo that = (NormalAuthInfo) o;
        return enabled == that.enabled
                && accountLocked == that.accountLocked
                && accountExpired == that.accountExpired
                && credentialsExpired == that.credentialsExpired
                && Objects.equals(identityId, that.identityId)
                && Objects.equals(identityName, that.identityName)
                && Objects.equals(authKey, that.authKey)
                && Objects.equals(authMode, that.authMode)
                && Objects.equals(credentials, that.credentials)
                && Objects.equals(salt, that.salt)
                && Objects.equals(userTypes, that.userTypes)
                && Objects.equals(authorities, that.authorities);
    }

    @Override
    public int hashCode() {
        return Objects.hash(identityId, identityName, authKey, authMode, credentials, salt, userTypes,
                enabled, accountLocked, accountExpired, credentialsExpired, authorities);
    }
}
